import subprocess
import pkg_resources

from submodules.common.lib.json_ import dict_to_json_file

dict_to_json_file()
def get_installed_packages(exclude=None):
    if exclude is None:
        exclude = []
    packages = pkg_resources.working_set
    return [dist for dist in packages if dist.key not in exclude]


def save_requirements(exclude_packages, filename='requirements.txt'):
    with open(filename, 'w') as f:
        for package in get_installed_packages(exclude_packages):
            f.write(f"{package.key}=={package.version}\n")

        # 定义你想要排除的包名列表


exclude_packages = ['unwanted-package1', 'unwanted-package2']
# 保存过滤后的包列表到文件  
save_requirements(exclude_packages)